package com.tianquan.client.loadBalan;

import com.tianquan.client.loadBalan.strategy.LoadBalancer;
import com.tianquan.client.loadBalan.strategy.LoadBalancerEnum;
import com.tianquan.common.instance.ServiceInstance;

/**
 * @Author: tianquan
 * @date: 2024-11-04  12:20
 * @Description: 阻塞负载均衡客户端
 */
public class BlockingLoadBalancerClient extends LoadBalancerClient {

    public BlockingLoadBalancerClient(LoadBalancerEnum type) {
        super(type);
    }

    public BlockingLoadBalancerClient() {
    }

    @Override
    public ServiceInstance choose(String serviceName) {
        // 从工厂获取具体的负载均衡器
        LoadBalancerEnum type = getType();
        LoadBalancer loadBalancer = LoadBalancerFactory.getLoadBalancer(type);
        // 调用负载均衡器选择实例
        return loadBalancer.choose(serviceName);
    }

}
